/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package upc.jfactory.scp.form;

import com.icesoft.faces.component.ext.taglib.MethodBindingString;
import com.icesoft.faces.component.menubar.MenuItem;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import upc.jfactory.scp.bl.facade.MenuFacade;
import upc.jfactory.scp.jpa.bean.Menu;

/**
 *
 * @author Diego Tovar
 */
public class FormMenu {

    private List<MenuItem> listaMenu;
    private List<Menu> listaJpa;
   
    public FormMenu() {

        MenuFacade menuFacade = MenuFacade.getInstance();
 FacesContext ctx = FacesContext.getCurrentInstance();


        HttpSession session =  (HttpSession) ctx.getExternalContext().getSession(true);
        char grupo = ((String)session.getAttribute("grupo")).charAt(0);
        listaJpa = menuFacade.listarMenus(grupo);
        listaMenu = new ArrayList<MenuItem>();

        for(int i=0;i<listaJpa.size();i++)
        {
            MenuItem menu= new MenuItem();

            menu.setValue(listaJpa.get(i).getDescripcion());
            MethodBindingString methodBindingString = new MethodBindingString(listaJpa.get(i).getLink());
            menu.setAction(methodBindingString);
            listaMenu.add(menu);

        }

    }

    public List<Menu> getListajpa() {
        return listaJpa;
    }

    public void setListajpa(List<Menu> listajpa) {
        this.listaJpa = listajpa;
    }

  

    public List<MenuItem> getListamenu() {
        return listaMenu;
    }

    public void setListamenu(List<MenuItem> listamenu) {
        this.listaMenu = listamenu;
    }
    



}
